// 获取全局应用程序实例对象
const app = getApp();
const {get,post} = app.utils.request;
const {user_order_list} = app.utils.config;

// 创建页面实例对象
Page({
	// 页面的初始数据
	data: {
		title: 'my',
		avatarUrl: '',
		nickName: '',
		orderList: [],
		pagination: {
			total: 0
		}
	},

	// 生命周期函数--监听页面加载
	onLoad() {
		var that = this;

		wx.getUserInfo({
			success: function(res) {
				var userInfo = res.userInfo
				var nickName = userInfo.nickName
				var avatarUrl = userInfo.avatarUrl
				that.setData({
					avatarUrl: avatarUrl,
					nickName: nickName
				});
			}
		})

		post({path: `${user_order_list}`}, {merchant_id: 1})
		.then((res) => {
			if (res.ret == 0) {
				var list = that.data.orderList;
				for (var i = 0; i < res.data.list.length; i++) {
					list.push(res.data.list[i]);
				}
				that.setData({
					orderList: list,
					pagination: res.data.pagination
				});
			}
		});
	},

	// 页面分享设置
	onShareAppMessage() {
		return {
			title: 'share title',
			path: 'pages/my/my',
		};
	},

	goEvaluate(evt) {
		const {id} = evt.target.dataset;
		wx.navigateTo({
			url: `/pages/evaluate/evaluate?id=${id}`
		});
	},

	goRefund(evt){
		const {id} = evt.target.dataset;
		wx.navigateTo({
			url: `/pages/refund/refund?id=${id}`
		});
	}
});